<script setup lang="tsx">
import { PropType } from 'vue'
import { CurdData } from '@/api/logisticsCompany/types'
import { Descriptions } from '@/components/Descriptions'
import { useCrudSchemas } from '@/hooks/web/useCrudSchemas'
import useSchema from './hooks/useSchema'
import { getFieldEnumApi } from '@/api/logisticsRules'
import { SchemaConfig } from '@/api/global/types'

defineProps({
  currentRow: {
    type: Object as PropType<Nullable<CurdData>>,
    default: () => null
  }
})
const fieldEnum = ref<Record<string, any>>({})
const allSchemas = ref<Record<string, any>>({
  detailSchema: []
})
getFieldEnumApi({ field: 'all' }).then((res) => {
  fieldEnum.value = res.data
  const schemaConfig: SchemaConfig = {
    fieldEnum: fieldEnum.value
  }

  const { crudSchemas } = useSchema(schemaConfig)
  const { allSchemas: newSchemas } = useCrudSchemas(crudSchemas)

  // 合并新的数据，确保不改变原有数据的类型
  allSchemas.value.detailSchema = newSchemas.detailSchema || []
})
</script>

<template>
  <Descriptions :schema="allSchemas.detailSchema" :data="currentRow || {}" />
</template>
